package examples.computations;

import org.apache.commons.functor.UnaryFunction;

import util.DA;
import util.DiffComputation;
import util.Real;
import util.Int;
import util.functors.AccociBinaryOP;
import util.functors.BinaryOperator;

public class LineofSight extends DiffComputation<DA, Real, Int> {

	public LineofSight() {
		init = new Real(0.5);

		oplus = new AccociBinaryOP<Int>() {

			@Override
			public Int evaluate(Int left, Int right) {
				return new Int(left.get() + right.get());
			}

			@Override
			public Int id() {
				return new Int(0);
			}

		};

		otimes = new AccociBinaryOP<Real>() {
			@Override
			public Real evaluate(Real left, Real right) {
				return new Real(Math.max(left.get(), right.get()));
			}

			@Override
			public Real id() {
				return new Real(Integer.MIN_VALUE);
			}
		};

		g = new UnaryFunction<Real, Int>() {
			@Override
			public Int evaluate(Real obj) {
				return new Int(0);
			}

		};

		p = new BinaryOperator<DA, Real, Int>() {

			@Override
			public Int evaluate(DA x, Real c) {
				if (c.get() <= ((x.a * 1.0) / x.d))
					return new Int(1);
				else
					return new Int(0);
			}

			@Override
			public DA getInstanceOfT0() {
				return new DA(1, 1);
			}

		};

		q = new UnaryFunction<DA, Real>() {
			@Override
			public Real evaluate(DA da) {
				return new Real((da.a * 1.0) / da.d);
			}

		};

	}

}
